<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    //创建对象
    var draw = {
        arr: [],
        logs: [],
        show: function () {
            var random = Math.random() * this.arr.length;//等价于Math.random() * (arr.length - 0) + 0;
            // 再转为整数 去掉小数点
            var index = parseInt(random)
            // 随机下标的数组元素
            console.log(this.arr[index]);

            //选做题
            //抽完取出待抽池 使用数组对象的splice()方法
            var item = this.arr.splice(index, 1)[0]
            //记录时间日志
            var now = new Date();
            var str = "时间：" + now.getFullYear() + "年" + now.getMonth() + "月" + now.getDate() + "日"
             + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds() + "抽中了" + item
            //返回数组的第随机个元素
            console.log(str);
            //存入时间日志
            this.logs.push(str)
        },
        push: function (name) {
            this.arr.push(name);
        }
    }
    //加入待抽签数组
    draw.push("曹操")
    draw.push("孙权")
    draw.push("曹丕")
    draw.push("刘备")
    draw.push("张飞")
    draw.push("关羽")
    //随机抽取一个
    draw.show()
    //随机抽取一个
    draw.show()
    //随机抽取一个
    draw.show()
    //增加显示时间日志的功能
    draw.showLogs = function () {
        console.log(this.logs)
    }
    //显示抽签的日志
    draw.showLogs();
// 选做内容

</script>

</html>